<?php

namespace app\admin\controller;

use app\admin\model\auth\Roles;
use app\Request;

class Role extends Base
{

    public function list(Request $request){


        if($request->isAjax() && $request->isGet()){

            $result=Roles::select()->toArray();

           return $this->success($result);
        }



        return view('role/list');
    }

    public function add(Request $request): \think\response\View|\think\response\Json
    {

        if($request->isAjax() && $request->isPost()){
             $data=input('post.');
            $result=Roles::create($data);
            return $this->success();
        }

        return view('role/add');
    }

    public function edit(Request $request): \think\response\View|\think\response\Json
    {

        if($request->isAjax() && $request->isPost()){
            $data=input('post.');
            $result=Roles::where(['id'=>input('id')])->update($data);
            return $this->success($result);
        }

        $info=Roles::where(['id'=>input('id')])->find();

        return view('role/edit',['info'=>$info]);
    }

    public function del(Request $request){


        Roles::where(['id'=>$request->post('id')])->delete();
        return $this->success();
    }

}